package com.tanhua.manage.controller;

import com.tanhua.manage.service.UserService;
import com.tanhua.manage.vo.UserFreezingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 接口名称：用户数据翻页
     * 接口路径：GET/manage/users
     */
    @GetMapping("users")
    public ResponseEntity<Object> findByPage(@RequestParam(defaultValue = "1") Integer page,
                                             @RequestParam(defaultValue = "10") Integer pagesize){
        return userService.findByPage(page, pagesize);
    }


    /**
     *接口名称：用户基本资料
     * 接口路径：GET/manage/users/:userID
     */
    @GetMapping("/users/{userID}")
    public ResponseEntity<Object> findById(@PathVariable("userID") Long userId){
        return userService.findById(userId);
    }

    /**
     *接口名称：视频记录翻页
     * 接口路径：GET/manage/videos
     */
    @GetMapping("/videos")
    public ResponseEntity<Object> findVideosList(@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer pagesize,long uid){
        return userService.findVideosList(page,pagesize,uid);
    }

    /**
     * 接口名称：动态分页,动态审核
     * 接口路径：GET/manage/messages
     */
    @GetMapping("messages")
    public ResponseEntity<Object> findMovementsList(
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize, Long uid, String state){
        ResponseEntity<Object> movementsList =
                uid!=null? userService.findMovementsList(page, pagesize, uid)
                        :userService.dynamicReview(page, pagesize,state);
        return movementsList;
    }

    /**
     *接口名称：动态详情
     * 接口路径：GET/manage/messages/:id
     */
    @GetMapping("messages/{id}")
    public ResponseEntity<Object> findMovementsById(@PathVariable("id") String publishId){
        return userService.findMovementsById(publishId);
    }


    /**
     *接口名称：评论列表翻页
     * 接口路径：GET/manage/messages/comments
     * */
    @GetMapping("messages/comments")
    public ResponseEntity<Object> findMovementsByIdfindCommentsById(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize,
            @RequestParam(name = "messageID") String publishId){
        return userService.findCommentsById(publishId, page, pagesize);
    }

    /**
     * 接口名称：动态通过
     * 接口路径：POST/manage/messages/pass
     */
    @PostMapping("messages/pass")
    public ResponseEntity<Object> cheakPass(@RequestBody String[] uid) {
        return userService.cheakPass(uid);
    }

    /**
     * 接口名称：动态拒绝
     * 接口路径：POST/manage/messages/pass
     */
    @PostMapping("messages/reject")
    public ResponseEntity<Object> cheakReject(@RequestBody String[] uid) {
        return userService.cheakReject(uid);
    }

    /**
     * 接口名称：用户冻结操作
     * 接口路径：POST/manage/users/freeze
     * @param vo
     * @return String 操作成功
     */
    @PostMapping("/users/freeze")
    public ResponseEntity<Object> freezingUser(@RequestBody UserFreezingVo vo){
        return userService.freezingUser(vo);
    }

    /**
     * 接口名称：用户解冻操作
     * 接口路径：POST/manage/users/unfreeze
     * @param param
     * @return String 操作成功
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity<Object> unFreezingUser(@RequestBody Map<String, Object> param){
        Integer userId = (Integer) param.get("userId");
        String reasonsForThawing = (String) param.get("reasonsForThawing");
        return userService.unFreezingUser(userId,reasonsForThawing);
    }
}
